home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 02 Useful Techniques / 05 Carlisle / Listing1.cpp
Encoding:
Text File  |  2001-12-09  |  1.2 KB  |  38 lines

  1. /* Copyright (C) Phil Carlisle, 2001. 
  2.  * All rights reserved worldwide.
  3.  *
  4.  * This software is provided "as is" without express or implied
  5.  * warranties. You may freely copy and compile this source into
  6.  * applications you distribute provided that the copyright text
  7.  * below is included in the resulting source code, for example:
  8.  * "Portions Copyright (C) Phil Carlisle, 2001"
  9.  */
  10. CreatureMachine::CreatureMachine()
  11. {
  12.     // add all variables to the variable list
  13.     AddVariable("Health",VAR_INTEGER,&m_Health);
  14.     AddVariable("EnemyLocation",VAR_POSITION,&m_Enemy;
  15.     
  16.     // now add conditions (may reference variables)
  17.     AddCondition("InRange",LESSTHAN,"EnemyLocation",100);
  18.     AddCondition("LowHealth",LESSTHAN,"Health", 50);
  19.     
  20.     // now add all the actions (may be referenced by the // states)    
  21.     AddAction("IdleAction");
  22.     AddAction("FightAction");
  23.     AddAction("FleeAction");
  24.     
  25.     // now add all the states
  26.     AddState("Idle","IdleAction");
  27.     AddState("Fight","FightAction");
  28.     AddState("Flee","FleeAction");
  29.  
  30.     // now add all the transitions (may reference states 
  31.     // and variables)
  32.     // transitions syntax : <condition-name> <start state>
  33.     // <end state>
  34.     AddTransition("In Range","Idle","Fight");
  35.     AddTransition("Low Health","Fight","Flee");
  36.  
  37. };
  38.